package com.xs.designpattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xs
 */
public class PartyImpl implements Party {
    private final List<PartyMember> members;

    public PartyImpl() {
        members = new ArrayList<>();
    }

    /**
     * 行为
     * @param actor  actor
     * @param action action
     */
    @Override
    public void act(PartyMember actor, Action action) {
        //遍历组织成员 对当前行为做出反应
        for (PartyMember member : members) {
            if (!member.equals(actor)) {
                member.partyAction(action);
            }
        }
    }

    @Override
    public void addMember(PartyMember member) {
        members.add(member);
        member.joinedParty(this);
    }
}
